package com.vlefen.springcloud.grpc.example.client;

import com.google.protobuf.util.JsonFormat;
import com.vlefen.springcloud.grpc.GRpc;
import com.vlefen.springcloud.grpc.grpc.GRpcType;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Rest {

    @Autowired
    @GRpc(serviceDefinition = GreeterGrpc.class, type = GRpcType.BlockingStub)
    private GreeterGrpc.GreeterBlockingStub blockingStub;

    @GetMapping("/")
    @ResponseBody
    public HelloReply test(@RequestParam String name) {
        HelloReply helloReply= blockingStub.sayHello(HelloRequest.newBuilder().setName(name).build());
        return helloReply;
    }
}
